package com.sbr.seb.wicket.page;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

import com.sbr.seb.entity.checklist.Question;
import com.sbr.seb.entity.composants.Category;

/**
 * Homepage
 */
public class CheckListManagerPage extends BasePage {

	private static final long serialVersionUID = 1L;

    /**
	 * Constructor that is invoked when page is invoked without a session.
	 * 
	 * @param parameters
	 *            Page parameters
	 */
    public CheckListManagerPage() {
    	super();
    	List<Category> categoryList = new ArrayList<Category>();
    	categoryList.add(new Category("Contrôles globaux", "Controles de la globalité"));
    	categoryList.add(new Category("Contrôles compilation", "Controles de la compilation"));
    	
    	add( new ListView<Category>("categoryList", categoryList) {

			@Override
			protected void populateItem(ListItem<Category> item) {
				Category category = (Category) item.getModelObject();
				item.add(new Label("name", category.getName()));
				item.add(new Label("description", category.getDescription()));
				
				if (item.getIndex() %2 == 0) {
					item.add(new SimpleAttributeModifier("class", "even"));
				} else {
					item.add(new SimpleAttributeModifier("class", "odd"));
				}
				
			}
    		
    	});
    	
    	add(new BookmarkablePageLink("newCheckListCategoryLink", NewCheckListCategoryPage.class));
    	
    	List<Question> questionList = new ArrayList<Question>();
    	questionList.add(new Question("Reste t-il des anomalies bloquantes ?", "Non"));
    	questionList.add(new Question("Le code compile t-il ?", "Oui"));
    	
    	add( new ListView<Question>("questionList", questionList) {

			@Override
			protected void populateItem(ListItem<Question> item) {
				Question question = item.getModelObject();
				item.add(new Label("questionCategory", (question.getCategory()==null?"X":question.getCategory().getName())));
				item.add(new Label("question", question.getQuestion()));
				item.add(new Label("questionDefaultAnswer", question.getDefaultAnswer()));
			}
    		
    	});
    	
    	add(new BookmarkablePageLink("addCheckListQuestionLink", AddCheckListQuestionPage.class));
    }
}
